<!doctype html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>吸顶效果</title>
    <style>
        *{
            padding: 0;
            margin: 0;
        }
        body{
            height: 2000px;
 background: url("images/haraware_kid.png");
        }
        /*吸顶效果*/
        #top{
            line-height: 50px;
            background: grey;
            color: yellow;
            font-size: 20px;
            text-align: center;
        }
        #top::selection{
            color: maroon;
            background:#fff;
        }
        /*隐藏头部*/
        #header{
            width: 100%;
            line-height: 50px;
            background: rgba(0,0,0,.4);
            text-align: center;
            box-shadow: 0 0 5px black;
            position: fixed;
            left: 0;
            top: -103px;
        }
        #header.top{
            top: 0;
            transition-top:0.5;
        }
        .txt:hover{
            box-shadow: 0 0 2px red;
        }
        .btn:hover{
            box-shadow: 0 0 2px red;
        }
        .txt{
            width: 190px;
            height:26px;
            vertical-align: middle;
            border:1px solid #ccc;
            border-right: 0;
            outline: none;
        }
        .btn{
            width: 35px;
            height:28px;
            vertical-align: middle;
            border:1px solid #ccc;
            border-left: 0;
            outline: none;
            cursor: pointer;
        }
        p{
            font-size: 20px;
            color:#ff0;
        }
    </style>
</head>
<body>
<div id="top">
    <p>搜索一下</p>
    <form action="">
        <input type="text" class="txt" value="iPhone 11"><input type="submit" value="搜索" class="btn">
    </form>
</div>
<div id="header">
    <p>搜索一下</p>
    <form action="">
        <input type="text" class="txt" value="iPhone 11"><input type="submit" value="搜索" class="btn">
    </form>
</div>
<script>
    //吸顶效果
    var oTop = document.getElementById('top');
    setTimeout(function(){
        oTop.style.display = 'none';//设置id为top的样式
    },100000000);
    var oHeader = document.getElementById('header');
    window.onscroll = function(){
        //获取窗口的滚动条位置
        var sScroll = document.body.scrollTop || document.documentElement.scrollTop;
        if(sScroll >= 400){
            oHeader.className = 'top';
        }else{
            oHeader.className = '';
        }
    }
</script>
</body>
</html>